package com.winqai.security.core;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.winqai.security.core.properties.SecurityProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * 配置读取文件信息的对象
 */
@Configuration
@EnableConfigurationProperties(SecurityProperties.class) //配置读取对象
public class SecurityCoreConfig {

//    private BrowserProperties browser = new BrowserProperties();
//
//    public void setBrowser(BrowserProperties browser) {
//        this.browser = browser;
//    }
//    public BrowserProperties getBrowser(){
//        return browser;
//    }

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }


    /**
     * 解决异常
     * org.springframework.http.converter.HttpMessageNotWritableException:
     * Could not write content: No serializer found for class com.google.
     * common.cache.CacheStats and no properties discovered to create
     * BeanSerializer (to avoid exception, disable
     * SerializationFeature.FAIL_ON_EMPTY_BEANS)
     * @return
     */
    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    }
}
